package com.csd.action.document;

import java.io.File;

import com.csd.helper.ActionResult;
import com.csd.serviceImpl.DocumentRecordService;

/**
 * 
 * Action:上传工程文档
 * 
 * @author csd
 * @version 1.0
 * 
 * <br>
 *          修订时间：2009-12-17 <br>
 *          修改原因：创建文件 <br>
 *          修改人：刘世彬 <br>
 * 
 */

public class DocumentUploadAction {
	private DocumentRecordService service;

	private File upload;

	private String stage;

	/** 文档名称=name.suffix */
	public String uploadFileName;

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getStage() {
		return stage;
	}

	public void setStage(String stage) {
		this.stage = stage;
	}

	public DocumentRecordService getService() {
		return service;
	}

	public void setService(DocumentRecordService service) {
		this.service = service;
	}

	public String execute() {
		String result = ActionResult.fail;

		// 文档存储时，只保留后缀名
		String suffix = this.uploadFileName.substring(this.uploadFileName
				.lastIndexOf('.'));
		// 调用服务层，上传文档
		if (service.uploadDocument(this.upload, suffix, this.stage))
			result = ActionResult.success;

		return result;
	}

}
